package twice.class01;

/**
 * @author ywb
 * @Description:
 * @date 2023/6/15 16:31
 */
public class Class02_Bubble {
    public static void bubbleSort(int[] arr) {
    if(arr==null||arr.length <2){return;}
    for(int i = arr.length - 1;i >= 0;i--){
        for(int j = 0;j < i;j++){
        if(arr[j] > arr[j+1]){
            swap(arr,j,j+1);
        }
        }
    }
    }

    public static void swap(int[] arr, int i, int j) {
        int tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }

    public static void main(String[] args) {
        int[] arr = new int[]{8,7,5,2,6,4,3,1,9};
        bubbleSort(arr);
        for (int i : arr) {
            System.out.print(i);
        }
    }
}
